//****************************************************************
//* Copyright (c) 2008 Ford Motor Company. All Rights Reserved.
//*
//* $$Workfile:   CurrencyFacade.java  $$
//* $$Revision:   1.2  $$
//* $$Author:   TMALDON4  $$
//* $$Date:   Mar 11 2009 07:39:14  $$
//*
//*****************************************************************
package ar.com.ford.it.fullEconomics.facade;

import java.math.BigDecimal;
import java.util.Collection;
import ar.com.ford.it.fullEconomics.exception.FullEconomicsException;
import ar.com.ford.it.fullEconomics.logic.CurrencyLogic;
import ar.com.ford.it.fullEconomics.logic.CurrencyValuesLogic;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesg01Plant;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesm01Currency;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesm02Currvalue;
import ar.com.ford.it.fullEconomics.wslx.FullEconomicsWslxUser;

public class CurrencyFacade {

    /**
     * Obtiene todas las monedas existentes
     * 
     * @return
     * @throws FullEconomicsException
     */
    public Collection<Teesm01Currency> getAllCurrency()
            throws FullEconomicsException {

        CurrencyLogic logic = new CurrencyLogic();

        Collection<Teesm01Currency> ret = logic.findAllCurrency();

        return ret;
    }

    /**
     * Obtiene las monedas por codigo
     * 
     * @param currCode
     * @return
     * @throws FullEconomicsException
     */
    public Teesm01Currency findCurrencyByCode(String currCode)
            throws FullEconomicsException {
        CurrencyLogic logic = new CurrencyLogic();
        Teesm01Currency result = new Teesm01Currency();
        result = logic.findCurrencyByCode(currCode);
        return result;
    }

    /**
     * Valida el rango de currency Value a crear
     * 
     * @param currCode
     * @return
     * @throws FullEconomicsException
     */
    public boolean validRange(Teesg01Plant plant, String codeOrig,
                              String codeDest, String fechaIn, String fechaOut)
            throws FullEconomicsException {
        CurrencyValuesLogic logic = new CurrencyValuesLogic();
        boolean result;
        result = logic.validRange(plant, codeOrig, codeDest, fechaIn, fechaOut);
        return result;
    }

    /**
     * Da de alta el Currency pasado por parametro
     * 
     * @param currency
     * Currency a dar de alta
     * @param user
     * Usuario que da de alta el Currency
     * @throws FullEconomicsException
     */
    public void createCurrency(Teesm01Currency currency,
                               FullEconomicsWslxUser user)
            throws FullEconomicsException {
        CurrencyLogic logic = new CurrencyLogic();

        logic.createCurrency(currency, user);
    }

    /**
     * Da de alta el Currency Value pasado por parametro
     * 
     * @param currencyOrig
     * Currency a dar de alta
     * @param user
     * Usuario que da de alta el Currency
     * @throws FullEconomicsException
     */
    public void createCurrencyValue(String currencyOrig, String currencyDest,
                                    String convertRate, String fechaIn,
                                    String fechaOut, FullEconomicsWslxUser user)
            throws FullEconomicsException {
        CurrencyValuesLogic logic = new CurrencyValuesLogic();

        logic.createCurrencyValue(currencyOrig, currencyDest, convertRate,
                fechaIn, fechaOut, user);
    }

    /**
     * Da de alta el Currency Value pasado por parametro. Esta funcion se usa
     * para reinsertar el currency borrado en el action cuando se quiere hacer
     * un update cambiando la fecha de inicio y el rango introducido no es valido.
     * 
     * @param currencyValue
     * Currency Value a dar de alta
     * @throws FullEconomicsException
     */
    public void reInsertCurrencyValue(Teesm02Currvalue currencyValue)
            throws FullEconomicsException {
        CurrencyValuesLogic logic = new CurrencyValuesLogic();

        logic.reInsertCurrencyValue(currencyValue);
    }

    /**
     * Actualiza el Currency pasado por parametro
     * 
     * @param currency
     * Currency a actualizar
     * @param user
     * Usuario que actualiza el Currency
     * @throws FullEconomicsException
     */
    public void updateCurrency(Teesm01Currency currency,
                               FullEconomicsWslxUser user)
            throws FullEconomicsException {
        CurrencyLogic logic = new CurrencyLogic();

        logic.updateCurrency(currency, user);
    }

    /**
     * Actualiza el Currency Value pasado por parametro
     * 
     * @param currency
     * Currency a actualizar
     * @param user
     * Usuario que actualiza el Currency
     * @throws FullEconomicsException
     */
    public void updateCurrencyValue(String currencyOrig, String currencyDest,
                                    String convertRate, String fechaIn,
                                    String fechaOut, FullEconomicsWslxUser user)
            throws FullEconomicsException {
        CurrencyValuesLogic logic = new CurrencyValuesLogic();

        logic.updateCurrencyValue(currencyOrig, currencyDest, convertRate,
                fechaIn, fechaOut, user);
    }

    /**
     * Elimina el ecnomicSource pasado por parametro
     * 
     * @param currency
     * Currency a eliminar
     * @throws FullEconomicsException
     */
    public void deleteCurrency(Teesm01Currency currency)
            throws FullEconomicsException {
        CurrencyLogic logic = new CurrencyLogic();

        logic.deleteCurrency(currency);
    }

    /**
     * Elimina el Currency Value pasado por parametro
     * 
     * @param currencyValue
     * Currency Value a eliminar
     * @param confirmMovePrevDate
     * booleano para mover la fecha del registro anterior
     * @throws FullEconomicsException
     */
    public boolean deleteCurrencyValue(Teesm02Currvalue currencyValue, String confirmMovePrevDate)
            throws FullEconomicsException {
        CurrencyValuesLogic logic = new CurrencyValuesLogic();
        boolean borro;

        borro = logic.deleteCurrencyValue(currencyValue, confirmMovePrevDate);
        return borro;
    }

    /**
     * Busca Currencys segun code
     * 
     * @param code
     * @return
     * @throws FullEconomicsException
     */
    public Collection<Teesm01Currency> findCurrencys(String code)
            throws FullEconomicsException {
        CurrencyLogic logic = new CurrencyLogic();
        Collection<Teesm01Currency> ret = logic.findCurrencies(code);

        return ret;
    }

    /**
     * Busca CurrencyValues segun fecha, y codigos de origen y destino
     * 
     * @param Fecha
     * @param codigo
     * origen
     * @param Fecha
     * destino
     * @return
     * @throws FullEconomicsException
     */
    public Collection<Teesm02Currvalue> findCurrencyValues(Teesg01Plant plant,
                                                           String fecha,
                                                           String codeOrigen,
                                                           String codeDestino)
            throws FullEconomicsException {
        CurrencyValuesLogic logic = new CurrencyValuesLogic();
        Collection<Teesm02Currvalue> ret = logic.findCurrencieValues(plant,
                fecha, codeOrigen, codeDestino);

        return ret;
    }
    
    public BigDecimal getCurrentConvertRate(Teesm01Currency orig,
                                            Teesm01Currency dest,
                                            Teesg01Plant plant)
            throws FullEconomicsException {
        CurrencyValuesLogic logic = new CurrencyValuesLogic();
        BigDecimal ret = logic.getCurrentConvertRate(orig, dest, plant);
        return ret;
    }

}
